$(document).ready(
	function(){
		// bind click event of button list
		$('#PreviewBtn').click(preview);
	});

function preview(){
	// pop up
	$( "#dialog:ui-dialog" ).dialog( "destroy" );
	var baseUrl = '/index.php/spin/preview';
	var content = $('#input').text();
	var request = $.ajax({
		type : 'POST',
		url : baseUrl,
		data : {
			content : content
		},
		dataType : 'html'
	});
	
	request.done(function(msg){
		$( "#dialog-modal" ).html(msg);
	});
	request.fail(function(jqXHR, textStatus) {
		alert("Request failed: " + jqXHR.responseText);
	});
	
	$( "#dialog-modal" ).dialog({
		height: 500,
		modal: true,
		title:'Preview article that generated by article spinner bee!',
		width:500,
		show:'slide'
	});

}